home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C19 / Sorted.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.4 KB  |  58 lines

  1. //: C19:Sorted.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Testing template specialization
  7. #include "Sorted.h"
  8. #include "Urand.h"
  9. #include "../arraySize.h"
  10. #include <iostream>
  11. #include <string>
  12. using namespace std;
  13.  
  14. char* words[] = {
  15.   "is", "running", "big", "dog", "a",
  16. };
  17. char* words2[] = {
  18.   "this", "that", "theother",
  19. };
  20.  
  21. int main() {
  22.   Sorted<int> is;
  23.   Urand<47> rand;
  24.   for(int i = 0; i < 15; i++)
  25.     is.push_back(rand());
  26.   for(int l = 0; l < is.size(); l++)
  27.     cout << is[l] << ' ';
  28.   cout << endl;
  29.   is.sort();
  30.   for(int l = 0; l < is.size(); l++)
  31.     cout << is[l] << ' ';
  32.   cout << endl;
  33.  
  34.   // Uses the template partial specialization:
  35.   Sorted<string*> ss;
  36.   for(int i = 0; i < asz(words); i++)
  37.     ss.push_back(new string(words[i]));
  38.   for(int i = 0; i < ss.size(); i++)
  39.     cout << *ss[i] << ' ';
  40.   cout << endl;
  41.   ss.sort();
  42.   for(int i = 0; i < ss.size(); i++)
  43.     cout << *ss[i] << ' ';
  44.   cout << endl;
  45.   
  46.   // Uses the full char* specialization:
  47.   Sorted<char*> scp;
  48.   for(int i = 0; i < asz(words2); i++)
  49.     scp.push_back(words2[i]);
  50.   for(int i = 0; i < scp.size(); i++)
  51.     cout << scp[i] << ' ';
  52.   cout << endl;
  53.   scp.sort();
  54.   for(int i = 0; i < scp.size(); i++)
  55.     cout << scp[i] << ' ';
  56.   cout << endl;
  57. } ///:~
  58.